import 'core-js/stable';
import 'regenerator-runtime/runtime';
import React from 'react';
import { render } from 'react-dom';
import { isRoot, modules } from 'stripes-config';
import localforage from 'localforage';
import { GlobalProvider } from '@jiatuan/hooks';
import App from './App';

export default async function init(props) {
  const { container } = props;
  const localOkapi = await localforage.getItem('curTenant');

  const restProps = {};

  if (isRoot) {
    const [basic] = modules.app;
    const qiankunProps = basic.getModule();
    Object.assign(restProps, qiankunProps);
  }

  render(
    <GlobalProvider {...{ ...props, ...restProps, localOkapi }}>
      <App {...{ ...props, localOkapi }} />
    </GlobalProvider>,
    container ? container.querySelector('#root') : document.querySelector('#root')
  );
}